<%@page import="java.util.Map"%>
<%@page import="com.hospital.util.DbUtil"%>
<%@page import="com.hospital.util.Pagination"%>
<%@ page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="images/main.css" rel="stylesheet" type="text/css" />
<link  href="../css/style.css" rel="stylesheet" type="text/css" />
<title></title>
<script type="text/javascript">
	function checkAll(field) {
		var selectFlags = document.getElementsByName("selectFlag");
		for ( var i = 0; i < selectFlags.length; i++) {
			selectFlags[i].checked = field.checked;
		}
	}

	function add() {
		window.location.href = "cure_add.jsp";
	}
	function del() {
		var selectFlags  = document.getElementsByName("selectFlag");
		var flag = false;
		for (var i=0; i<selectFlags.length; i++) {
			if (selectFlags[i].checked) {
				flag = true;
				break;
			}
		}
		if (!flag) {
			alert("请选择需要删除的信息！");
			return;
		}
		if (window.confirm("确认删除吗？")) {
			with (document.getElementById("form")) {
				action="CureServlet?method=del";
				method="post";
				submit();
			}
		}
	}
	function modify() {
		var selectFlags = document.getElementsByName("selectFlag");
		var count = 0;
		var j = 0;
		for ( var i = 0; i < selectFlags.length; i++) {
			if (selectFlags[i].checked) {
				j = i;
				count++;
			}
		}
		if (count == 0) {
			alert("请选择需要修改的信息！");
			return;
		}
		if (count > 1) {
			alert("一次只能修改一个信息！");
			return;
		}
		window.location.href = "cure_modify.jsp?id=" + selectFlags[j].value;;
	}
</script>
</head>
<body>
	<jsp:include page="right_top.jsp"></jsp:include>
	
	<!-- TOP START -->
	<div id="right_font">
		<img src="images/main_14.gif" /> 您现在所在的位置：首页 → 就诊信息管理 → <span
			class="bfont">就诊信息维护</span>
	</div>
	<!-- TOP END -->
	
	<!-- MAIN START -->
	<form name="form" id="form">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td height="30">
					<jsp:include page="top_banner.jsp"></jsp:include>
				</td>
			</tr>
			<tr>
				<td>
					<!-- table context start -->
					<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c9c9c9">
						<tr>
							<td width="100px;" height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">选择</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">编号</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">挂号单号</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">病患名称</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">病情</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">开药</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">价格</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">检查项目</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">检查费用</span></strong>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<strong><span class="STYLE1">操作</span></strong>
								</div>
							</td>
						</tr>
						<%
							/**
							 * 分页begin
							 */
							final int pageSize = 15; // 一页显示 15 条记录
		
							int pageNum = 1; // 当前页数
							int pageCount = 1; // 总页数
		
							int recordCount = 0; // 总记录数
		
							String strAbsPath = application.getRealPath(request.getRequestURI()); // 获得当前文件的绝对路径名
							int endIndex = strAbsPath.length();
							int beginIndex = strAbsPath.lastIndexOf("\\") + 1;
							String pageUrl = strAbsPath.substring(beginIndex, endIndex); // 获取当前文件名，如：xxx.jsp,或者 xxx.html
		
							try {
								// 从地址栏参数取当前页数
								if (request.getParameter("pageNum") == null) {
									pageNum = 1;
								} else {
									pageNum = Integer.parseInt(request.getParameter("pageNum"));
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
		
							recordCount = DbUtil.getCount("t_cure");
							// 计算总页数
							pageCount = (recordCount + pageSize - 1) / pageSize;
							// 本页从 startRecord 行开始
							int startRecord = (pageNum - 1) * pageSize;
							/**
							 * 分页end
							 */
							int num = 1;
							String sql = "select * from t_cure order by id desc limit "
													+ startRecord + " ," + pageSize;
											
							List<Map<String, Object>> list = DbUtil.find(sql);
							Map<String, Object> map = null;
							for (int i = 0; i < list.size(); i++) {
								map = (Map<String, Object>)list.get(i);
						%>
						<tr>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3">
										<input type="checkbox" name="selectFlag" value="<%=map.get("id")%>" >
									</span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=num++%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("orderid")%></span>
								</div>
							</td>
							<%
								String sql_patientname = "select name from t_order where oid = '" + map.get("orderid") + "'";
								String patientname = DbUtil.getString(sql_patientname); 
							%>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=patientname %><br></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("cases")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("drug")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("drugmoney")%></span>
								</div>
							</td>
							<%
								String sql_item = "select name from t_checklist where id = '" + map.get("item") + "'";
								String item = DbUtil.getString(sql_item); 
							%>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=item%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3"><%=map.get("itemmoney")%></span>
								</div>
							</td>
							<td height="22" bgcolor="#FFFFFF">
								<div align="center">
									<span class="STYLE3">
										<a href="print.jsp?id=<%=map.get("id")%>">查看票据</a> -- 
										<a href="print2.jsp?id=<%=map.get("id")%>">查看费用</a>
									</span>
								</div>
							</td>
						</tr>
						<%
							}
						%>
					</table>
				<!-- table context end -->
				</td>
			</tr>
			<tr>
				<td height="35">
					<!-- page start -->
					<table width="100%" border="0" cellspacing="0" cellpadding="1">
						<tr>
							<td width="75%" valign="top" class="STYLE1">
								<div align="right">
									<%=Pagination.getPagination(pageNum, pageCount, recordCount,pageUrl)%>&nbsp;&nbsp;
								</div>
							</td>
						</tr>
					</table>
					<!-- page end -->
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
